package cn.springcloudtest.service;

import cn.springcloudtest.mapper.LogMapper;
import cn.springcloudtest.pojo.Log;
import cn.springcloudtest.utils.Constants;
import cn.springcloudtest.utils.EmptyUtils;
import cn.springcloudtest.utils.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName:springcloud-topic-provider
 * @Author:赵伟杰
 * @Date:2021年09月05日 12:01
 */
@RestController
public class RestLogService {

    @Resource
    private LogMapper logMapper;

    @RequestMapping("/local/getLogById")
    public Log getLogById(@RequestParam Integer id) throws Exception {
        return logMapper.getLogById(id);
    }


     @RequestMapping("/local/getLogListByMap")
    public List<Log> getLogListByMap(@RequestBody Map<String, Object> param) throws Exception {
        System.out.println("我是Log1");
        return logMapper.getLogListByMap(param);
    }


     @RequestMapping("/local/getLogCountByMap")
    public Integer getLogCountByMap(@RequestBody Map<String, Object> param) throws Exception {
        return logMapper.getLogCountByMap(param);
    }


     @RequestMapping("/local/AddLog")
    public Integer addLog(@RequestBody Log log) throws Exception {
        return logMapper.insertLog(log);
    }


     @RequestMapping("/local/ModifyLog")
    public Integer modifyLog(@RequestBody Log log) throws Exception {
        return logMapper.updateLog(log);
    }


     @RequestMapping("/local/DeleteLogById")
    public Integer deleteLogById(@RequestParam Integer id) throws Exception {
        return logMapper.deleteLogById(id);
    }

     @RequestMapping("/local/queryLogPageByMap")
    public Page<Log> queryLogPageByMap(@RequestBody Map<String, Object> param) throws Exception {
        Integer pageNo = (Integer) param.get("pageNo");
        Integer pageSize = (Integer) param.get("pageSize");
        Integer total = logMapper.getLogCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.PageNumber.pageNo : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.PageNumber.pageSize : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        page.setRows(logMapper.getLogListByMap(param));
        return page;
    }

}
